package com.zh.chat.controller;

import com.zh.chat.gui.LoginFrame;
import com.zh.chat.gui.MainFrame;
import com.zh.chat.net.TCPDTO;
import com.zh.chat.net.UDPDTOImpl;
import com.zh.chat.net.UdpDTO;
import com.zh.chat.service.NetService;
import com.zh.chat.util.ConfigUtil;

public class Main {
	public static void main(String[] args) {
		ConfigUtil config = new ConfigUtil();
		String lookAndFeel = config.getString("LookAndFeel");
		
		NetService netService = new NetService();
		UdpDTO udpDTO = new UDPDTOImpl(config);
		TCPDTO tcpDTO = new TCPDTO(config);
		netService.setNetDTO(udpDTO);
		netService.setTcpDTO(tcpDTO);
		
		ClientContext context = new ClientContext();
		netService.setClientContext(context);
		context.setNetService(netService);
		
		LoginFrame loginFrame = new LoginFrame();
		loginFrame.setClientContext(context);
		loginFrame.setConfig(config);
		
		MainFrame mainFrame = new MainFrame(lookAndFeel);
		mainFrame.setClientContext(context);
		context.startUDPReciver();//启动UDP命令接收线程
		context.setLoginFrame(loginFrame);
		context.setMainFrame(mainFrame);
		context.getNetService().requestIp();
		context.getLoginFrame().setVisible(true);
	}
}
